<?php
class Organizations extends Admin_Controller
{
	public function __construction()
	{
		parent::__construction();
	}
	
	public function  index()
	{
		$category = new Category($_GET['agency_id']);
		$data['contents'] = $category->child->get_by_related_structure('type', 'organization')->content->get_page(50);
		$this->template->build('admin/index', $data);
	}
	
	public function form($id = NULL)
	{
		$data['category'] = new Category;
		$data['category']->get_by_related_structure('type', 'organization');
		$data['content'] = new Content($id);
		$this->template->build('admin/form', $data);
	}
	
	public function save($id = NULL)
	{
		if($_POST)
		{
			$content = new Content($id);
			$content->from_array($_POST);
			$content->save();
			set_notify('success', lang('save_data_complete'));
		}
		redirect('organizations/admin/organizations/?agency_id='.$_GET['agency_id']);
	}
	
	public function delete($id)
	{
		if($id)
		{
			$content = new Content($id);
			$content->delete();
			set_notify('success', lang('delete_data_complete'));
		}
		redirect('organizations/admin/organizations/?agency_id='.$_GET['agency_id']);
	}
}
